/*
 * pwms.h
 *
 * Created: 28/01/2014 23:52:21
 *  Author: usuario
 */ 

#ifndef PWMS_H_
#define PWMS_H_

#include <rtos.h>

// 1 enable, 0 disable.
//  PWM_CHANNEL_0 -> Due D34
#define	PWM_CHANNEL0_ENABLED	1
//  PWM_CHANNEL_1 -> Due D36
#define	PWM_CHANNEL1_ENABLED	1
//  PWM_CHANNEL_2 -> Due D38
#define	PWM_CHANNEL2_ENABLED	1
//  PWM_CHANNEL_3 -> Due D40
#define	PWM_CHANNEL3_ENABLED	1
//  PWM_CHANNEL_4 -> Due PWM9
#define	PWM_CHANNEL4_ENABLED	1
//  PWM_CHANNEL_5 -> Due PWM8
#define	PWM_CHANNEL5_ENABLED	1
//  PWM_CHANNEL_6 -> Due PWM7
#define	PWM_CHANNEL6_ENABLED	1
//  PWM_CHANNEL_7 -> Due PWM6
#define	PWM_CHANNEL7_ENABLED	1

// Channels used = max pwm
#define MAX_PWM				4

#define PERIOD_VALUE			10000

#define PWM_FREQUENCY_LOW		20
#define PWM_FREQUENCY_HIGH		300

typedef void *pwm_if;

void   PWM_setup( void );
pwm_if PWM_conf (uint8_t channel, uint8_t pwm_frequency, uint32_t init_duty);

void PWM_update_duty_async(	pwm_if pwm, uint32_t duty, 
								portTickType block_time_ticks, xSemaphoreHandle notification_semaphore);

#define  PWM_update_duty(pwm, duty, block_time_ticks) PWM_update_duty_async((pwm), (duty), (block_time_ticks), (NULL))
								

#endif /* PWMS_H_ */